package com.study.controller;

import com.study.dao.AdminDao;
import com.study.dao.UserDao;
import com.study.domain.Admin;
import com.study.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("admin")
public class AdminIndexController {

    private AdminDao adminDao = new AdminDao();
    private UserDao userDao = new UserDao();

    @PostMapping("login")
    public String login(String name, String password, Model model, HttpSession session) {
        Admin admin = adminDao.login(name, password);
        if (null == admin) {
            model.addAttribute("error", "用户名或者密码错误");
            return "error";
        }
        return "redirect:user.action";
    }

    @RequestMapping("user")
    public String user(Model  model) {
        List<User> list = userDao.list();
        model.addAttribute("list",list);
        return "user";
    }


}
